package com.leimingkun.mq.listen;

import com.leimingkun.mq.conf.TtlQueueConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class RabbitListen {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @RabbitListener(queues = TtlQueueConfig.DLQ_QUEUE)
    public void listen(String message, Channel channel,@Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException {
        System.out.println("leiQueue:"+message);
        channel.basicAck(deliveryTag,false);
    }
}
